﻿using KPI.Entity;
using System.Collections.Generic;

namespace KPI.Data
{
    public class AppDictData
    {
        private static object lockObj = new object();
        private static Dictionary<EnumDictType, Dictionary<int, string>> dics = new Dictionary<EnumDictType, Dictionary<int, string>>();
        public AppDictData() { }

        public static void Update(EnumDictType dictType, List<Tbl_DictData> datas)
        {
            if (datas == null)
                return;
            Dictionary<int, string> tmp = new Dictionary<int, string>();
            foreach (var item in datas)
            {
                tmp[item.dict_value] = item.dict_label;
            }
            lock (lockObj)
            {
                dics[dictType] = tmp;
            }
        }

        public static string GetLabel(EnumDictType dictType, int value)
        {
            lock (lockObj)
            {
                if (!dics.ContainsKey(dictType))
                {
                    return "";
                }
                if (!dics[dictType].ContainsKey(value))
                {
                    return "";
                }
                return dics[dictType][value];
            }
        }
        public static Dictionary<int, string> GetList(EnumDictType dictType)
        {
            lock (lockObj)
            {
                if (!dics.ContainsKey(dictType))
                {
                    return null;
                }
                return dics[dictType];
            }
        }
    }
}
